<?php
class EvaluatedothersController extends AppController{
	function getRoomBoardRate($patientid){
		$this->view='Json';
		App::import('Model', 'Roomrate');
		App::import('Model', 'Patient');
		App::import('Model', 'Casetype');
		
		//-----------------Patient---------------
		$Patient=new Patient();		
		$field=array('category', 'finaldiagnosis');
		$condition=array('id'=>$patientid);
		$patient=$Patient->find('first', array('conditions'=>$condition, 'fields'=>$field));
		
		$hospitalLevel=$patient['Patient']['category'];
		$finalDiagnosis=explode(';',$patient['Patient']['finaldiagnosis']);		
		//---------------------------------------
		//-----------------Casetype---------------
		$Casetype=new Casetype();		
		$field=array('casetype');
		$condition=array('icd'=>$finalDiagnosis[0]);
		$casetype=$Casetype->find('first', array('conditions'=>$condition, 'fields'=>$field));
		$type=$casetype['Casetype']['casetype'];				
		//---------------------------------------
		//-----------------Casetype---------------
		$Roomrate=new Roomrate();
		$condition=array('hospitallevel'=>$hospitalLevel, 'casetype'=>$type);
		$roomrate=$Roomrate->find('all', array('conditions'=>$condition));				
		//---------------------------------------
		
		$this->set('data', $roomrate);									
		$this->set('json', 'data');
	}
	function getLimitOperatingRoom($patientid, $claimid){
		$this->view='Json';
		
		App::import('Model', 'Patient');
		App::import('Model', 'Evaluatedsurgeon');
		App::import('Model', 'Operatingroomrate');
		//-----------------Patient---------------
		$Patient=new Patient();		
		$field=array('category', 'finaldiagnosis');
		$condition=array('id'=>$patientid);
		$patient=$Patient->find('first', array('conditions'=>$condition, 'fields'=>$field));
		
		$hospitalLevel=$patient['Patient']['category'];
		$finalDiagnosis=explode(';',$patient['Patient']['finaldiagnosis']);		
		//---------------------------------------
		//-------------Evaluatedsurgeon----------
		$Evaluatedsurgeon=new Evaluatedsurgeon();
		$condition=array('claimid'=>$claimid);
		$field=array('rvs', 'rvu', 'pcf');
		$surgeon=$Evaluatedsurgeon->find('first', array('conditions'=>$condition, 'fields'=>$field));
		$rvu=$surgeon['Evaluatedsurgeon']['rvu'];
		//---------------------------------------
		//-------------OperatingroomRate----------
		$Operatingroomrate=new Operatingroomrate();
		if($hospitalLevel=='1'){
			$condition=array('hospitallevel'=>$hospitalLevel);
		}		
		else{
			if($rvu>=0 && $rvu<=30){
				$condition=array('hospitallevel'=>$hospitalLevel, 'rvu_from >='=>0, 'rvu_to <='=>30);
			}
			else if($rvu>=31 && $rvu<=80){
				$condition=array('hospitallevel'=>$hospitalLevel, 'rvu_from >='=>31, 'rvu_to <='=>80);
			}
			else if($rvu>=81 && $rvu<=600){
				$condition=array('hospitallevel'=>$hospitalLevel, 'rvu_from >='=>81, 'rvu_to <='=>600);
			}			
		}		
		$operatingroom=$Operatingroomrate->find('all', array('conditions'=>$condition));		
		//---------------------------------------
		$this->set('data', $operatingroom);									
		$this->set('json', 'data');
	}
	function insert($data){
		$this->data['Evaluatedother']['claimid']=$data[0];
		$this->data['Evaluatedother']['particular']=$data[1];
		$this->data['Evaluatedother']['quantity']=$data[2];
		$this->data['Evaluatedother']['unit_price']=str_replace(',', '', $data[3]);
		$this->data['Evaluatedother']['actual_charge']=str_replace(',', '', $data[4]);
		$this->data['Evaluatedother']['claim_hospital']=str_replace(',', '', $data[5]);
		$this->data['Evaluatedother']['claim_patient']=str_replace(',', '', $data[6]);
		$this->data['Evaluatedother']['service_type']=$data[7];		
		$this->data['Evaluatedother']['status']=1;
				
		$this->Evaluatedother->create();
		$this->Evaluatedother->save($this->data);
	}
	function setStatus($id, $status){
		$this->data['Evaluatedother']['id']=$id;
		$this->data['Evaluatedother']['status']=$status;
		
		$this->Evaluatedother->save($this->data);
	}	
	function getTotalClaimHospital($claimid){
		$this->view='Json';
			
		$condition=array('claimid'=>$claimid, 'service_type'=>1, 'status'=>1);
		$field=array('SUM(claim_hospital) as claim_hospital');
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition, 'fields'=>$field));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getTotalXrayClaimHospital($claimid){
		$this->view='Json';
			
		$condition=array('claimid'=>$claimid, 'service_type'=>2, 'status'=>1);
		$field=array('SUM(claim_hospital) as claim_hospital');
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition, 'fields'=>$field));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getTotalOperatingClaimHospital($claimid){
		$this->view='Json';
			
		$condition=array('claimid'=>$claimid, 'service_type'=>3, 'status'=>1);
		$field=array('SUM(claim_hospital) as claim_hospital');
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition, 'fields'=>$field));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getTotalConfinementClaimHospital($claimid){
		$this->view='Json';
			
		$condition=array('claimid'=>$claimid, 'service_type'=>4, 'status'=>1);
		$field=array('SUM(claim_hospital) as claim_hospital');
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition, 'fields'=>$field));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getConfinement($claimid){
		$this->view='Json';
		
		$condition=array('claimid'=>$claimid, 'service_type'=>4);
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getOperating($claimid){
		$this->view='Json';
		
		$condition=array('claimid'=>$claimid, 'service_type'=>3);
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getXray($claimid){
		$this->view='Json';
		
		$condition=array('claimid'=>$claimid, 'service_type'=>2);
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function getRoomBoard($claimid){
		$this->view='Json';
		
		$condition=array('claimid'=>$claimid, 'service_type'=>1);
		$data=$this->Evaluatedother->find('all', array('conditions'=>$condition));
		
		$this->set('data', $data);									
		$this->set('json', 'data');
	}
	function update(){
		$id=$_POST['id'];
		$quantity=$_POST['quantity'];
		$unit_price=$_POST['unit_price'];
		$total=$quantity*$unit_price;
		
		$this->data['Evaluatedother']['id']=$id;
		$this->data['Evaluatedother']['quantity']=$quantity;
		$this->data['Evaluatedother']['unit_price']=$unit_price;		
		$this->data['Evaluatedother']['claim_hospital']=$total;
		
		$this->Evaluatedother->save($this->data);
	}
}
?>